/**
 * 如果用户没开启通知权限、引导用户开启 */
export function setPermissions() {
	let lang = getApp().globalData.lang
	var let_title = '通知权限开启提醒';
	var let_content = '您还没有开启通知权限，无法接受到消息通知，请前往设置！';
	var let_btn = '去设置';
	var let_btn2 = '暂不';
	if(lang=='zh'){
		let_title = '通知权限开启提醒';
		let_content = '您还没有开启通知权限，无法接受到消息通知，请前往设置！';
		let_btn = '去设置';
		let_btn2 = '暂不';
	}else{
		let_title = 'Напоминание об открытии разрешений на уведомления.';
		let_content = 'Вы ещё не включили разрешение на уведомления.，Не могут получать уведомления о сообщениях.，Пожалуйста, перейдите на страницу настроек!';
		let_btn = 'Да';
		let_btn2 = 'Нет';
	}
	
	
	// #ifdef APP-PLUS 
	if (plus.os.name == 'Android') {
		var main = plus.android.runtimeMainActivity();
		var pkName = main.getPackageName();
		var uid = main.getApplicationInfo().plusGetAttribute("uid");
		var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");
		if (NotificationManagerCompat == null) {
			NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat");
		}
		var areNotificationsEnabled = NotificationManagerCompat.from(main).areNotificationsEnabled();
		console.log(areNotificationsEnabled)
		if (!areNotificationsEnabled) {
			uni.setStorageSync('message_permission', 0);
			uni.showModal({
				title: let_title,
				content: let_content,
				showCancel: true,
				confirmText: let_btn,
				confirmColor:'#36d',
				cancelText:let_btn2,
				cancelColor:'#999',
				success: function(res) {
					if (res.confirm) {
						var Intent = plus.android.importClass('android.content.Intent');
						var Build = plus.android.importClass("android.os.Build");
						if (Build.VERSION.SDK_INT >= 26) {
							var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
							intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);
						} else if (Build.VERSION.SDK_INT >= 21) {
							var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
							intent.putExtra("app_package", pkName);
							intent.putExtra("app_uid", uid);
						} else {
							intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
							var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
							intent.setData(uri);
						}
						main.startActivity(intent);
					}
				}
				
			});
		}else{
			uni.setStorageSync('message_permission', 1);
		}
	} else if (plus.os.name == 'iOS') {
		var isOn = undefined;
		var types = 0;
		var app = plus.ios.invoke('UIApplication', 'sharedApplication');
		var settings = plus.ios.invoke(app, 'currentUserNotificationSettings');
		if (settings) {
			types = settings.plusGetAttribute('types');
			plus.ios.deleteObject(settings);
		} else {
			types = plus.ios.invoke(app, 'enabledRemoteNotificationTypes');
		}
		plus.ios.deleteObject(app);
		isOn = (0 != types);
		if (isOn == false) {
			uni.setStorageSync('message_permission', 0);
			uni.showModal({
				title: let_title,
				content: let_content,
				showCancel: true,
				confirmText: let_btn,
				confirmColor:'#36d',
				cancelText:let_btn2,
				success: function(res) {
					if (res.confirm) {
						var app = plus.ios.invoke('UIApplication', 'sharedApplication');
						var setting = plus.ios.invoke('NSURL', 'URLWithString:', 'app-settings:');
						plus.ios.invoke(app, 'openURL:', setting);
						plus.ios.deleteObject(setting);
						plus.ios.deleteObject(app);
					}
				}
			});
		}else{
			uni.setStorageSync('message_permission', 1);
		}
	}
	// #endif 
}